//
//  HitMap.h
//  atomtrace
//
//  Created by Yuntao Ou on 4/20/14.
//  Copyright (c) 2014 Yuntao Ou. All rights reserved.
//

#ifndef __ATOMTRACE_HIT_MAP_H_
#define __ATOMTRACE_HIT_MAP_H_

#include "Vector3.h"
#include "Color.h"
#include "HitRecord.h"

namespace AtomTrace {
    
    // HitPoint for progressive photon map, not confuse with hit record
    // In page 3 of the paper
    typedef struct HitPoint {
        int brdf;       // BRDF index
        int pix;        // Pixel indices
        float r;        // current photon radius
        float npht;       // accumulated photon count
        
        Vector3 pos;    // Hit location
        Vector3 norm;   // Normal at pos
        Vector3 dir;    // ray direction
        Color wgt;      // Pixel weight
        Color flux;     // accumulated reflected flux
        
        HitPoint(){ wgt.Set(1.0f); }
        HitPoint(const HitPoint& other);
        
        const HitPoint& operator=(const HitPoint& rhs);
        const HitPoint& operator=(HitRecord& rhs);
        
    }HitPoint; // typdef struct HitPoint
    
    class HitMap
    {
        int w,h;
        int _addr;
        int hit_size; // cache sizeof hitpoint
        
        void StoreHitPoint(int addr, const HitPoint& hit);
        void LoadHitPoint(int addr, HitPoint &hit) const;
    public:
        HitMap();
        
        void Set(int i, int j, HitPoint & hit);
        void Set(int pix, HitPoint & hit);
        
        void Get(int pix, HitPoint &hit) const;
        void Get(int i, int j, HitPoint &hit) const;
        
    }; // class HitMap
    
} // namespace AtomTrace

#endif //__ATOMTRACE_HIT_MAP_H_
